﻿@using TD.Common.Kendo.Mvc5.Grid
@using TD.Common.Kendo.Mvc5.Common
@using TD.Common.Kendo.Mvc5.Grid.Filters

@section head{
    <link href="@Url.Content("~/Content/td/td.kendo.grid.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/td/td.kendo.grid.js")"></script>
}

@{
    var filterRow = new FilterRow(Html);
}

@(Html.Kendo().Grid<TD.CTS.Data.Entities.Trial>()
    .Init("Grid")
    .Editable()
    .Columns(columns =>
    {
        columns.Buttons(buttons =>
        {
            buttons.HeaderCustom().Tag(ButtonTag.a).Url(Url.Action("Edit", "Trials")).Title("Добавить").ImageCssClass("k-add");
            buttons.Custom().Tag(ButtonTag.a).Url(Url.Action("Edit", "Trials") + "/#:Code#").Title("Изменить").ImageCssClass("k-edit");
            buttons.Delete();
            //buttons.Custom().Tag(ButtonTag.a).Url(Url.Action("RolesEdit", "Trials") + "/#:Code#").Title("Роли и стоимость").ImageCssClass("k-i-custom");
        }, filterRow).Width(80);
        columns.Bound(e => e.Name, filterRow).Width(200).Title("Наименование");
        columns.ForeignKey(e => e.Status, (System.Collections.IEnumerable)ViewBag.Statuses, "Key", "Value").Width(100).Title("Статус");
        filterRow.AddCell(new EmptyFilterCell());
        columns.Bound(e => e.CreateDate).Width(265).Title("Дата создания").Format("{0:dd.MM.yyyy HH:mm}");
        filterRow.AddCell(new DateRangeFilterCell("CreateDate"));
        columns.ForeignKey(e => e.AdministratorLogin, (System.Collections.IEnumerable)ViewBag.Users, "Login", "FullName").Width(200).Title("Администратор");
        filterRow.AddCell(new CheckBoxFilterCell("OwnTrialsOnly", "Только свои"));
        columns.Bound(e => e.VersionDate).Width(180).Title("Дата модификации").Format("{0:dd.MM.yyyy HH:mm}");
        filterRow.AddCell(new EmptyFilterCell());
        columns.ForeignKey(e => e.AuthorLogin, (System.Collections.IEnumerable)ViewBag.Users, "Login", "FullName").Width("100%").Title("Автор модификации");
        filterRow.AddCell(new EmptyFilterCell());
    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Model(model =>
        {
            model.Id(e => e.Code);
        })
        .Read(read => read.Action("GetTrials", "Trials").Data("kendo_grid_getfilters"))
        .Destroy(destroy => destroy.Action("DeleteTrial", "Trials"))
        .Events(events => events.Error("kendo_grid_error_handler"))
     )

)

<script>
    $(document).ready(function () {
        var grid = $("#Grid");
        kendo_grid_init(grid, true, '@Html.Raw(filterRow.HtmlFilterRow())');
    });

</script>

